package com.atguigu.gmall.user.service.impl;

import com.atguigu.gmall.common.util.MD5;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.model.user.UserInfo;
import com.atguigu.gmall.user.mapper.UserAddressMapper;
import com.atguigu.gmall.user.mapper.UserInfoMapper;
import com.atguigu.gmall.user.service.UserInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 李旭
 * @Time: 14:34
 * @Description:
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {


    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private UserAddressMapper userAddressMapper;
    //校验登录
    @Override
    public UserInfo login(UserInfo userInfo) {
        return  userInfoMapper.selectOne(new QueryWrapper<UserInfo>()
                .eq("login_name", userInfo.getLoginName())
                .eq("passwd", MD5.encrypt(userInfo.getPasswd())));
        //明文  123456      密文 202cb962ac59075b964b07152d234b70
    }
    //收货地址集合
    @Override
    public List<UserAddress> getUserInfoAddress(String userId) {
        return userAddressMapper.selectList(new QueryWrapper<UserAddress>()
          .eq("user_id",userId));
    }

    public static void main(String[] args) {

        //加盐 ：菜不咸 加点盐
        System.out.println(MD5.encrypt("123"));

        //   e10adc3949ba59abbe56e057f20f883e
        //   202cb962ac59075b964b07152d234b70
        //   202cb962ac59075b964b07152d234b70

    }
}
